package com.program.cloudmanage.tripteam.controller;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.program.cloudmanage.tripteam.domain.TripTeam;
import com.program.cloudmanage.tripteam.service.TripTeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RefreshScope
@RequestMapping("/TripTeam")
public class TripTeamController {
    @NacosInjected
    @Autowired
    private TripTeamService tripTeamService;

    @GetMapping("/TripTeam")
    public List<TripTeam> showTripTeams(){
        return tripTeamService.showTripTeams();
    }

    @GetMapping("/test")
    public String test(){
        return "hello world";
    }

    @PostMapping("/searchTripTeam")
    public TripTeam searchTripTeam(@RequestBody TripTeam tripTeam){
        return tripTeamService.searchTripTeam(tripTeam.getTeamid());
    }

    @GetMapping("searchTripTeamByname")
    public List<TripTeam> searchTripTeamByName(String keyword){
        return tripTeamService.searchTripTeamByname(keyword);
    }
    @PostMapping("/insertTripTeam")
    public String insertTripTeam(@RequestBody TripTeam tripTeam){
        tripTeamService.insertTripTeam(tripTeam);
        return "OK";
    }

    @PostMapping ("/deleteTripTeam")
    public String deleteTripTeam(@RequestBody TripTeam tripTeam){
        tripTeamService.deleteTripTeam(tripTeam.getTeamid());
        return "OK";
    }

    @PostMapping("/updateTripTeam")
    public String updateTripTeam(@RequestBody TripTeam tripTeam) {
        tripTeamService.updateTripTeam(tripTeam);
        return "OK";
    }
    @PostMapping("/updateCredit")
    public String updateCredit(@RequestBody TripTeam tripTeam) {
        tripTeamService.updateCredit(tripTeam);
        System.out.println(tripTeam.getCredit()+"aaa");
        return "OK";
    }

}